<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015/10/28
 * Time: 10:14
 */


namespace Dev;
use Org\Util\Rbac;
use Think\Controller;
class BaseController extends Controller {
    protected $operatorID=0;
    protected $currentGame='';
    protected $smarty=null;
    public function _empty(){
        $this->error('无效的操作');
    }


    function _initialize(){

        if( C('USER_AUTH_ON') && !in_array( MODULE_NAME,explode(",",C('NOT_AUTH_MODULE')))){
            //判断不通过认证
            if(!RBAC::AccessDecision()){
                if(!session(C('USER_AUTH_KEY'))){
                    session(C('USER_AUTH_KEY'),empty($_COOKIE[C('USER_AUTH_KEY')]) ? NULL : $_COOKIE[C('USER_AUTH_KEY')]);
                    session('username',empty($_COOKIE['username']) ? NULL : $_COOKIE['username']);
                    session('real_name',empty($_COOKIE['real_name']) ? NULL : $_COOKIE['real_name']);
                    session(C('ADMIN_AUTH_KEY'),empty($_COOKIE[C('ADMIN_AUTH_KEY')]) ? NULL : $_COOKIE[C('ADMIN_AUTH_KEY')]);
                    //session('_ACCESS_LIST',empty($_COOKIE['_ACCESS_LIST']) ? NULL : $_COOKIE['_ACCESS_LIST']);
                }
                //如果session没有值，则不通过
                if(!session(C('USER_AUTH_KEY'))){
                    //$this->jumpUrl=C("USER_AUTH_GETWAY");

                    $this->error("未登陆",U("Dev/Public/login"));
                    die;
                }

                $this->error("未授权该操作:".MODULE_NAME."_".CONTROLLER_NAME."_".ACTION_NAME);
            }
        }



        $this->smarty=getSmarty();
        $this->smarty->assign('staticRes','/devoops');
        $this->smarty->assign('version',time());
        session('operator',1);
        $this->operatorID   = session('operator');
        $game=session('game');
        if (!$game){
            session('game',GAME_FENGHUA);
        }
        $this->currentGame  = session('game');
        
    }



    /**
     * 添加日志
     * Author: shijy
     * @param $act 操作
     * @param $extra 具体操作数据
     */
    public function log($extra='',$act=''){
        $opt    = CONTROLLER_NAME."_".ACTION_NAME.'_'.$act;
        $user   = session('username');
        $adminLogM = M('gm_opt_log',null,DB_GM_CFG);
        $data=array(
            'user'      =>$user,
            'opt'       =>$opt,
            'extra'     =>$extra,
            'ip'        =>get_client_ip(),
            'addTime'   =>time()
        );
        $adminLogM->add($data);
    }

}